package bigraph.part;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import bigraph.model.Node;

/**
 * This is an abstract class that handles events management.
 * (basically it catches events triggered by model classes) 
 * All of the EditPart classes derive from it
 * 
 * @author mbyczkowski, s0789150
*/
public class AppAbstractEditPart extends AbstractGraphicalEditPart implements
		PropertyChangeListener {
	
	public void activate() {
	     super.activate();
	     ((Node) getModel()).addPropertyChangeListener(this);
	}
	public void deactivate() {
	     super.deactivate();
	     ((Node) getModel()).removePropertyChangeListener(this);
	}


	@Override
	protected IFigure createFigure() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void createEditPolicies() {
		// TODO Auto-generated method stub

	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		// TODO Auto-generated method stub

	}
	
    @Override
    public void performRequest(Request req) {
         if (req.getType().equals(RequestConstants.REQ_OPEN)) {
                try {
                      IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                      page.showView(IPageLayout.ID_PROP_SHEET);
                }
                catch (PartInitException e) {
                      e.printStackTrace();
                }
         }
    }

}
